﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Data;

namespace DAL
{
    public class BuyBudget
    {
        public static void insert(BuyBudgetEntity buyBudgeEnt)
        {
            DbHelper.ExecuteNonQuery("p_BuyBudget_insert", buyBudgeEnt.CompanyId, buyBudgeEnt.BudgetFee, buyBudgeEnt.Byear, buyBudgeEnt.Bmonth, buyBudgeEnt.IsHint);
        }

        public static void update(BuyBudgetEntity buyBudgeEnt)
        {
            DbHelper.ExecuteNonQuery("p_BuyBudget_update", buyBudgeEnt.Bid, buyBudgeEnt.CompanyId, buyBudgeEnt.BudgetFee, buyBudgeEnt.Byear, buyBudgeEnt.Bmonth, buyBudgeEnt.IsHint);
        }
        public static BuyBudgetEntity getById(int bid)
        {
            DataRow dr = DbHelper.ExecuteDataRow("p_BuyBudget_getById", bid);
            BuyBudgetEntity buyBudgeEnt = new BuyBudgetEntity();
            if (dr != null)
            {
                buyBudgeEnt.Bid = bid;
                buyBudgeEnt.CompanyId = Convert.ToInt32(dr["CompanyId"]);
                buyBudgeEnt.BudgetFee = Convert.ToDecimal(dr["BudgetFee"]);
                buyBudgeEnt.Byear = Convert.ToInt32(dr["Byear"]);
                buyBudgeEnt.Bmonth = Convert.ToInt32(dr["Bmonth"]);
                buyBudgeEnt.InputDt = Convert.ToDateTime(dr["InputDt"]);
                buyBudgeEnt.IsHint = Convert.ToBoolean(dr["IsHint"]);
            }
            return buyBudgeEnt;
        }
        public static bool isExistDate(int year,int month,int companyId)
        {
            if (Convert.ToInt32(DbHelper.ExecuteScalar("p_BuyBudget_isExistDate", year, month,companyId)) > 0)
                return true;
            else
                return false; ;
        }

        public static bool isHint(int companyId)
        {
            if (Convert.ToInt32(DbHelper.ExecuteScalar("p_BuyBudget_getIsHint", companyId)) > 0)
                return true;
            else
                return false; ;
        }
        public static void updateIsHint(int bid)
        {
            DbHelper.ExecuteNonQuery("p_BuyBudget_updateIsHint", bid);
        }
    }
}
